package com.sky.controller.User;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.shoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: ShoppingCartController
 * Package: com.sky.controller.User
 * Description:
 *
 * @Author: 葛龙
 * @Create 2025/2/28 15:33
 * @Version 1.0
 */
@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "用户购物车接口")
@Slf4j
public class ShoppingCartController {
    @Autowired
    private shoppingCartService shoppingCartService;

    /**
     * 用户向购物车里添加商品
     *
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("向购物车里面添加菜品")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        log.info("向购物车里面添加菜品{}", shoppingCartDTO);
        shoppingCartService.add(shoppingCartDTO);
        return Result.success();
    }

    /**
     * 查看购物车
     */
    @GetMapping("/list")
    @ApiOperation("查看购物车")
    public Result<List<ShoppingCart>> list() {
        log.info("查看购物车");
        List<ShoppingCart> list = shoppingCartService.list();
        return Result.success(list);
    }

    /**
     * 清空购物车
     *
     * @return
     */
    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result clean() {
        log.info("清空购物车");
        shoppingCartService.clean();
        return Result.success();

    }

    @PostMapping("/sub")
    @ApiOperation("删除购物车中的一个商品")
    public Result deleteCommodity(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("删除购物车中的一个商品{}", shoppingCartDTO);
        shoppingCartService.deleteCommodity(shoppingCartDTO);
        return Result.success();
    }


}
